package cn.how2go.api.mapper;

import cn.how2go.api.entity.UserDeviceState;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserDeviceStateMapper extends BaseMapper<UserDeviceState> {
    @Select("select id,name,role,phone, state,lon,lat,alt,lon2,lat2,qian.RecordTime as recordTime,systolic,diastolic,pulse,temp " +
            "from (" +
            "select per.id as id,name,role,phone, state,lon,lat,alt,lon2,lat2,RecordTime,deviceShou " +
            "from (" +
            "select mao.id as id, mao.name as name,mao.role as role,mao.phone as phone,mao.state as state,deviceMao,deviceShou " +
            "from (" +
            "select p.id as id,name,role,phone,p.state as state,d.id as deviceMao from person as p " +
            "LEFT JOIN device as d on p.id = d.OWNER and d.type=1) as mao " +
            "LEFT JOIN " +
            "(select name,role,phone,d.id as deviceShou from person as p " +
            "LEFT JOIN device as d on p.id = d.OWNER and d.type=2) as shou on mao.name = shou.name) as per  " +
            "left join (select id,lon,lat,alt,lon2,lat2,max(RecordTime) as RecordTime,device " +
            "from position group by device) as pos on per.deviceMao = pos.device) as qian " +
            "LEFT JOIN (select Systolic,Diastolic,Pulse,temp,max(RecordTime) as RecordTime,device " +
            "from wellness group by device) as hou on qian.deviceShou = hou.device")
    public List<UserDeviceState> listUserDeviceState();
}
